package com.gitee.ykr.lightweight.rpc.common.dto;


import com.gitee.ykr.lightweight.rpc.common.exception.ErrorCode;
import lombok.Data;

import java.io.Serializable;

/**
 * @author YKR
 * @Describe
 * @date 2021/8/23
 */
@Data
public class RespDTO<T> implements Serializable {

    private static final long serialVersionUID = 6395330487058794296L;

    private int code;
    private String msg;
    private T result;

    public RespDTO() {

    }

    public RespDTO(int code, String msg, T result) {
        this.code = code;
        this.msg = msg;
        this.result = result;
    }

    public static RespDTO fail(ErrorCode errorCode) {
        return new RespDTO( errorCode.getCode(), errorCode.getMsg(), null );
    }

    public static <T> RespDTO success(T result) {
        return new RespDTO( 1, "success", result );
    }

    public static RespDTO success() {
        return new RespDTO( 1, "success", null );
    }
}
